﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SvnLogParser.Localization;
using SvnLogParser.Utils;

namespace SvnLogParser
{
	public class FileChange
	{
		public const string ADDED = "A";
		public const string DELETED = "D";
		public const string MODIFIED = "M";
		public const string REPLACED = "R";

		private string changeType;
		public string ChangeType
		{
			get
			{
				return changeType;
			}
			set
			{
				if (!value.In(ADDED, DELETED, MODIFIED, REPLACED)) {
					throw new Exception(string.Format(strings.InvalidChangeTypeError, value));   
				}
				changeType = value;
			}
		}
		public string FilePath;
		public string FromFile;
		public int FromRev;
		private string longChangeType
		{
			get
			{
				switch (ChangeType) {
					case ADDED:
						return strings.w_added;
					case DELETED:
						return strings.w_deleted;
					case MODIFIED:
						return strings.w_modified;
					case REPLACED:
						return strings.w_replaced;
					default:
						if (changeType == null) return null;
						else throw new Exception(string.Format(strings.InvalidChangeTypeError, changeType));
				}
			}
		}

		public override string ToString()
		{
			string output = strings.w_file + " "  + longChangeType + " \"" + FilePath + "\"";
			if (!FromFile.IsNullOrEmpty()) {
				output += "(" + strings.w_from + " \"" + FromFile + "\", " + strings.w_revision + " " + FromRev + ")";
			}
			return output;
		}

		
	}
}
